// api : https://doc.apipost.net/docs/2b7238cf8464000d

const BASE_URL = 'https://d-paopao.bigchun.com'

export const request = (option = {}) => {
	return new Promise((resolve, reject) => {
		let token = uni.getStorageSync("token")

		uni.request({
			url: option.url.startsWith('http') ? option.url : BASE_URL + option.url,
			method: option.method ?? 'GET',
			data: option.data,
			header: {
				token: token
			},
			success(res) {
				if (res.data.code == 1) {
					resolve(res.data)
				}else if (res.data.code ==401) {
					resolve(res.data)
				} else {
					uni.showToast({
						icon: "none",
						title: res.data.msg
					})
				}
			},
			fail(e) {
				reject(e)
			}
		})

	})
}

export const get = (url, data, option = {}) => {
	option.method = 'GET';
	option.data = data;
	option.url = url;
	return request(option)
}
export const post = (url, data, option = {}) => {
	option.method = 'POST';
	option.data = data;
	option.url = url;
	return request(option)
}